<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unit tests for Media Plugin</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="qunit/connector.js"></script>
<script type="text/javascript" src="qunit/runner.js"></script>
<script type="text/javascript" src="js/tiny_mce_loader.js"></script>
<script>
var editor;

QUnit.config.reorder = false;
QUnit.config.autostart = false;

module("Media plugin", {
	autostart: false
});

test("Flash (strict output/relative urls)", function() {
	expect(4);

	editor.settings.media_strict = true;
	editor.settings.relative_urls = true;

	editor.setContent('<object width="425" height="355"><param name="movie" value="someurl"></param><param name="wmode" value="transparent"></param><embed src="someurl" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="someurl" type="application/x-shockwave-flash"><param name="wmode" value="transparent" /><param name="src" value="someurl" /></object></p>');

	editor.setContent('<object width="425" height="355"><param name="movie" value="someurl"></param><param name="wmode" value="transparent"></param><embed src="someurl" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="someurl" type="application/x-shockwave-flash"><param name="wmode" value="transparent" /><param name="src" value="someurl" /></object></p>');

	editor.setContent('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" /><embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" wmode="transparent" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="someurl" type="application/x-shockwave-flash"><param name="wmode" value="transparent" /><param name="src" value="someurl" /></object></p>');

	editor.setContent('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" />test<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" wmode="transparent" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="someurl" type="application/x-shockwave-flash"><param name="wmode" value="transparent" /><param name="src" value="someurl" />test</object></p>');
});

test("Flash (strict output/absolute urls)", function() {
	expect(10);

	editor.settings.media_strict = true;
	editor.settings.relative_urls = 0;

	editor.setContent('<object width="425" height="355"><param name="movie" value="someurl"></param><param name="wmode" value="transparent"></param><embed src="someurl" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="wmode" value="transparent" /><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /></object></p>');

	editor.setContent('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" /><embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" wmode="transparent" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="wmode" value="transparent" /><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /></object></p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" />');
	equal(editor.getContent(), '<p><object width="425" height="355" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /></object></p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" /><p>text</p>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /></object></p>\n<p>text</p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video"><p>text</p>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /></object></p>\n<p>text</p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" /><p>text</p>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /></object></p>\n<p>text</p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" /><p>text</p>');
	equal(editor.getContent(), '<p><object width="425" height="355" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /></object></p>\n<p>text</p>');

	editor.setContent('<object width="320" height="240"><embed src="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash" width="320" height="240" /></object>');
	equal(editor.getContent(), '<p><object width="320" height="240" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /></object></p>');

	editor.setContent('<object width="320" height="240" style="width: 320px; height: 240px;"><embed src="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash" width="320" height="240" /></object>');
	equal(editor.getContent(), '<p><object style="width: 320px; height: 240px;" width="320" height="240" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /></object></p>');

	editor.setContent('<object data="/tinymce/tinymce/trunk/tests/someurl" width="320" height="240" type="application/x-shockwave-flash"></object>');
	equal(editor.getContent(), '<p><object width="320" height="240" data="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /></object></p>');
});

test("Flash (compatible output/relative urls)", function() {
	expect(3);

	editor.settings.media_strict = false;
	editor.settings.relative_urls = true;

	editor.setContent('<object width="425" height="355"><param name="movie" value="someurl"></param><param name="wmode" value="transparent"></param><embed src="someurl" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" /><embed width="425" height="355" type="application/x-shockwave-flash" src="someurl" wmode="transparent" /></object></p>');

	editor.setContent('<object width="425" height="355"><param name="movie" value="someurl"></param><param name="wmode" value="transparent"></param><embed src="someurl" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" /><embed width="425" height="355" type="application/x-shockwave-flash" src="someurl" wmode="transparent" /></object></p>');

	editor.setContent('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" /><embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" wmode="transparent" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" /><embed width="425" height="355" type="application/x-shockwave-flash" src="someurl" wmode="transparent" /></object></p>');
});

test("Flash (compatible output/absolute urls)", function() {
	expect(9);

	editor.settings.media_strict = false;
	editor.settings.relative_urls = false;

	editor.setContent('<object width="425" height="355"><param name="movie" value="someurl"></param><param name="wmode" value="transparent"></param><embed src="someurl" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><embed width="425" height="355" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" wmode="transparent" /></object></p>');

	editor.setContent('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="someurl" /><embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" wmode="transparent" /></object>');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><embed width="425" height="355" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" wmode="transparent" /></object></p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" />');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /><embed width="425" height="355" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" flashvars="m=7286090&amp;v=2&amp;type=video" /></object></p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" />text');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /><embed width="425" height="355" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" flashvars="m=7286090&amp;v=2&amp;type=video" /></object>text</p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video">text');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /><embed width="425" height="355" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" flashvars="m=7286090&amp;v=2&amp;type=video" /></object>text</p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" />text');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /><embed width="425" height="355" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" flashvars="m=7286090&amp;v=2&amp;type=video" /></object>text</p>');

	editor.setContent('<embed type="application/x-shockwave-flash" width="425" height="355" src="someurl" flashvars="m=7286090&v=2&type=video" />text');
	equal(editor.getContent(), '<p><object width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><param name="flashvars" value="m=7286090&amp;v=2&amp;type=video" /><embed width="425" height="355" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" flashvars="m=7286090&amp;v=2&amp;type=video" /></object>text</p>');

	editor.setContent('<object width="320" height="240"><embed src="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash" width="320" height="240" /></object>');
	equal(editor.getContent(), '<p><object width="320" height="240" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><embed width="320" height="240" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" /></object></p>');

	editor.setContent('<object width="320" height="240" style="width: 320px; height: 240px;"><embed src="/tinymce/tinymce/trunk/tests/someurl" type="application/x-shockwave-flash" width="320" height="240" /></object>');
	equal(editor.getContent(), '<p><object style="width: 320px; height: 240px;" width="320" height="240" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/tinymce/tinymce/trunk/tests/someurl" /><embed style="width: 320px; height: 240px;" width="320" height="240" type="application/x-shockwave-flash" src="/tinymce/tinymce/trunk/tests/someurl" /></object></p>');
});

test("Quicktime (compatible output/relative urls)", function() {
	expect(1);

	editor.settings.media_strict = false;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="320" height="240" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0"><param name="src" value="test" /><embed type="video/quicktime" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p><object width="320" height="240" classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0"><param name="src" value="test" /><embed width="320" height="240" type="video/quicktime" src="test" /></object></p>');
});

test("WindowsMedia (compatible output/relative urls)", function() {
	expect(1);

	editor.settings.media_strict = false;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" width="320" height="240" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" id="test"><param name="src" value="test" /><embed id=\"test\" type="application/x-mplayer2" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p><object id=\"test\" width="320" height="240" classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"><param name="url" value="test" /><embed id=\"test\" width="320" height="240" type="application/x-mplayer2" src="test" /></object></p>');
});

test("WindowsMedia (detect type using classid)", function() {
	expect(1);

	editor.settings.media_strict = false;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" width="320" height="240" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" id="test"><param name="src" value="test" /><embed id=\"test\" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p><object id=\"test\" width="320" height="240" classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"><param name="url" value="test" /><embed id=\"test\" width="320" height="240" type="application/x-mplayer2" src="test" /></object></p>');
});

test("Realmedia (compatible output/relative urls)", function() {
	expect(1);

	editor.settings.media_strict = false;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa" width="320" height="240" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="test" /><embed type="audio/x-pn-realaudio-plugin" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p><object width="320" height="240" classid="clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="test" /><embed width="320" height="240" type="audio/x-pn-realaudio-plugin" src="test" /></object></p>');
});

test("Shockwave (compatible output/relative urls)", function() {
	expect(1);

	editor.settings.media_strict = false;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:166b1bca-3f9c-11cf-8075-444553540000" width="320" height="240" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0"><param name="src" value="test" /><embed type="application/x-director" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p><object width="320" height="240" classid="clsid:166b1bca-3f9c-11cf-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0"><param name="src" value="test" /><embed width="320" height="240" type="application/x-director" src="test" /></object></p>');
});

test("Video (attributes)", function() {
	expect(1);

	editor.settings.relative_urls = true;

	editor.setContent('<video src="320x240.ogg" autoplay loop controls></video>');
	equal(editor.getContent(), '<p><video width="320" height="240" src="320x240.ogg" autoplay="autoplay" loop="loop" controls="controls"></video></p>');
});

test("Video (fallback html)", function() {
	expect(1);

	editor.settings.relative_urls = true;

	editor.setContent('<video src="320x240.ogg">text<a href="#">link</a></video>');
	equal(editor.getContent(), '<p><video width="320" height="240" src="320x240.ogg">text<a href="#">link</a></video></p>');
});

test("Video (attributes/source)", function() {
	expect(1);

	editor.settings.relative_urls = true;

	editor.setContent('<video src="320x240.ogg" autoplay loop controls><source src="video.ogv" type="video/ogg; codecs=&quot;theora, vorbis&quot;" /><source src=\'video.3gp\' type=\'video/3gpp; codecs="mp4v.20.8, samr"\' /></video>');
	equal(editor.getContent(), '<p><video width="320" height="240" src="320x240.ogg" autoplay="autoplay" loop="loop" controls="controls"><source src="video.ogv" type="video/ogg; codecs=&quot;theora, vorbis&quot;" /><source src="video.3gp" type="video/3gpp; codecs=&quot;mp4v.20.8, samr&quot;" /></video></p>');
});

test("Video (source tag to src attr)", function() {
	expect(1);

	editor.settings.relative_urls = true;

	editor.setContent('<video><source src="video.ogv" /><source src=\'video.3gp\' type=\'video/3gpp; codecs="mp4v.20.8, samr"\' /></video>');
	equal(editor.getContent(), '<p><video width="320" height="240" src="video.ogv"><source src="video.3gp" type="video/3gpp; codecs=&quot;mp4v.20.8, samr&quot;" /></video></p>');
});

test("Flash (script/relative urls)", function() {
	expect(2);

	editor.settings.media_use_script = true;
	editor.settings.relative_urls = true;

	editor.setContent('<object width="425" height="355"><param name="movie" value="someurl"></param><param name="wmode" value="transparent"></param><embed src="someurl" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355" /></object>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeFlash({"wmode":"transparent","src":"someurl","width":"425","height":"355"});</' + 'script>\n</p>');

	editor.setContent('<p>\n<script type="text/javascript">writeFlash({"wmode":"transparent","src":"someurl","width":"425","height":"355"});</' + 'script>\n</p>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeFlash({"wmode":"transparent","src":"someurl","width":"425","height":"355"});</' + 'script>\n</p>');
});

test("Quicktime (script/relative urls)", function() {
	expect(2);

	editor.settings.media_use_script = true;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="320" height="240" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0"><param name="src" value="test" /><embed type="video/quicktime" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeQuickTime({"src":"test","width":"320","height":"240"});</' + 'script>\n</p>');

	editor.setContent('<p><script type="text/javascript">writeQuickTime({"src":"test","width":"320","height":"240"});</'+'script></p>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeQuickTime({"src":"test","width":"320","height":"240"});</'+'script>\n</p>');
});

test("WindowsMedia (script/relative urls)", function() {
	expect(2);

	editor.settings.media_use_script = true;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" width="320" height="240" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"><param name="src" value="test" /><embed type="application/x-mplayer2" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeWindowsMedia({"src":"test","width":"320","height":"240"});</' + 'script>\n</p>');

	editor.setContent('<p><script type="text/javascript">writeWindowsMedia({"src":"test","width":"320","height":"240"});</'+'script></p>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeWindowsMedia({"src":"test","width":"320","height":"240"});</'+'script>\n</p>');
});

test("RealMedia (script/relative urls)", function() {
	expect(2);

	editor.settings.media_use_script = true;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa" width="320" height="240" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="test" /><embed type="audio/x-pn-realaudio-plugin" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeRealMedia({"src":"test","width":"320","height":"240"});</' + 'script>\n</p>');

	editor.setContent('<p><script type="text/javascript">writeRealMedia({"src":"test","width":"320","height":"240"});</'+'script></p>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeRealMedia({"src":"test","width":"320","height":"240"});</'+'script>\n</p>');
});

test("Shockwave (script/relative urls)", function() {
	expect(2);

	editor.settings.media_use_script = true;
	editor.settings.relative_urls = true;

	editor.setContent('<object classid="clsid:166b1bca-3f9c-11cf-8075-444553540000" width="320" height="240" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0"><param name="src" value="test" /><embed type="application/x-director" width="320" height="240" src="test" /></object>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeShockWave({"src":"test","width":"320","height":"240"});</' + 'script>\n</p>');

	editor.setContent('<p><script type="text/javascript">writeShockWave({"src":"test","width":"320","height":"240"});</'+'script></p>');
	equal(editor.getContent(), '<p>\n<script type="text/javascript">writeShockWave({"src":"test","width":"320","height":"240"});</'+'script>\n</p>');
});

test("Iframe (relative urls)", function() {
	expect(2);

	editor.settings.relative_urls = true;

	editor.setContent('<iframe src="test"></iframe>');
	equal(editor.getContent(), '<p><iframe src="test" width="320" height="240"></iframe></p>');

	editor.setContent('<iframe frameborder="0" src="test" style="color: #FF0000" align="right" id="id" width="100" height="200"></iframe>');
	equal(editor.getContent(), '<p><iframe id="id" style="color: #ff0000;" src="test" frameborder="0" align="right" width="100" height="200"></iframe></p>');
});

test("Iframe (absolute urls)", function() {
	expect(2);

	editor.settings.relative_urls = false;

	editor.setContent('<iframe src="test"></iframe>');
	equal(editor.getContent(), '<p><iframe src="/tinymce/tinymce/trunk/tests/test" width="320" height="240"></iframe></p>');

	editor.setContent('<iframe frameborder="0" src="test" style="color: #FF0000" align="right" id="id" width="100" height="200"></iframe>');
	equal(editor.getContent(), '<p><iframe id="id" style="color: #ff0000;" src="/tinymce/tinymce/trunk/tests/test" frameborder="0" align="right" width="100" height="200"></iframe></p>');
});

test("Iframe invalid width/height", function() {
	editor.settings.relative_urls = false;

	editor.setContent('<iframe src="test" width="100px" height="200px"></iframe>');
	equal(editor.getContent(), '<p><iframe src="/tinymce/tinymce/trunk/tests/test" width="100" height="200"></iframe></p>');
});

test("Internal dataToHtml", function() {
	expect(1);

	editor.settings.media_use_script = false;
	editor.settings.relative_urls = true;

	equal(
		editor.plugins.media.dataToHtml({
			type: 'flash',
			params: {src: 'url'},
			video: {}
		}),

		'<object width="320" height="240" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="url" /><embed width="320" height="240" type="application/x-shockwave-flash" src="url" /></object>'
	);
});

test("Flash retain attribs", function() {
	expect(1);

	editor.settings.media_strict = true;
	editor.settings.relative_urls = true;

	editor.setContent('<object id="a1" name="b2" align="right" width="320" height="240" bgcolor="red" vspace="10" hspace="20" data="test" type="application/x-shockwave-flash" bgcolor="red"><param name="src" value="test" /></object>');
	equal(editor.getContent(), '<p><object id="a1" width="320" height="240" name="b2" align="right" hspace="20" vspace="10" bgcolor="red" data="test" type="application/x-shockwave-flash"><param name="src" value="test" /></object></p>');
});

test("Embedded Audio", function() {
	expect(1);
	editor.remove();
	initTiny({media_types: "embeddedaudio=wav"}, function() {
		editor.setContent('<embed height="20" width="100" type="audio/x-wav" controller="true" src="test.wav"/>');
		equal(editor.getContent(), '<p><embed width="100" height="20" type="audio/x-wav" src="test.wav" controller="true" /></p>');
	});
});

function initTiny(settings, load) {
	var default_settings = {
		mode : "exact",
		elements : "elm1",
		theme : "advanced",
		add_unload_trigger : false,
		document_base_url : '/tinymce/tinymce/trunk/tests/',
		plugins : 'media',
		init_instance_callback : function(ed) {
			editor = ed;
			load();
		}
	};
	var settings = tinymce.extend(default_settings, settings);
	tinyMCE.init(settings);
}

initTiny({}, QUnit.start);
</script>
</head>
<body>
	<h1 id="qunit-header">Unit tests for Media Plugin</h1>
	<h2 id="qunit-banner"></h2>
	<div id="qunit-testrunner-toolbar"></div>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests"></ol>

	<textarea id="elm1" name="elm1"></textarea>
	<div>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
	</div>
</body>
</html>
